//
//  BaseTabBarController.m
//  果库
//
//  Created by HZApple on 16/5/25.
//  Copyright © 2016年 hdu. All rights reserved.
//

#import "BaseTabBarController.h"

@interface BaseTabBarController ()

@end

@implementation BaseTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _loadSubViewCtrls];
     [self _createCustomTabBar];
    // Do any additional setup after loading the view.
}

- (void)_loadSubViewCtrls {
    
    NSArray *storyboardNames = @[@"Hot", @"Homepage", @"Message", @"Personal"];
    
    NSMutableArray *navs = [NSMutableArray array];
    
    for (NSString *name in storyboardNames) {
        
        //获取到故事板
        UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:name bundle:nil];
        
        //加载故事板中的导航控制器--initial Controller
        UINavigationController *nav = [storyBoard instantiateInitialViewController];
        
        [navs addObject:nav];
        
    }
  
    self.viewControllers = navs;
    
    
}

- (void)_createCustomTabBar {
    
    //移除系统自带的tabBar按钮
    for (UIView *view in self.tabBar.subviews) {

        if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            [view removeFromSuperview];
            
        }
        
    }
    
    CGFloat width = kScreenWidth / 4;
    
     NSArray *array = @[@"热门商品",@"主页",@"消息",@"个人"];
     
     
     
    for (NSInteger i = 0; i < 4; i++) {
        
        
         UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
         button.frame = CGRectMake(i * width, 0, width, kTabbarHeight);
        [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
        
        button.tag = i;
        
         [button setTitle:array[i] forState:UIControlStateNormal];
         [button setTitle:array[i] forState:UIControlStateHighlighted];
         [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
         [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
     
         
         button.backgroundColor = [UIColor blackColor];
        [self.tabBar addSubview:button];
        
        
    }

    
    
}

- (void)clickButton:(UIButton *)button {
     
     self.selectedIndex = button.tag;
     
     [UIView animateWithDuration:0.3 animations:^{
          
 
     }];
     
     
     
     
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
